var config = require('../config');
var utils  = require('../utils/function');
var Member = require('../model/member');
var aes    = require('../libs/aes');

module.exports.get = function (req, res, next) {
	var account  = req.query.account;
	var password = req.query.password;
	res.set({
		'X-Powered-By' : 'cjango.com'
	});
	if (!account) {
		res.json(utils.result(40001, '', 'Need Your Account'));
		return;
	} else if (!password) {
		res.json(utils.result(40002, '', 'Need Your Password'));
		return;
	}
	var ret = '';
	Member.query('SELECT * FROM go_member WHERE username = "' + account + '"', function (err, result) {
		if (err) {
			ret = utils.result(err, '', result);
		} else {
			if (utils.umd5(password) != result[0]['password']) {
				ret = utils.result(500, '', 'Password Error');
			} else {
				var sign = {
					uid : result[0]['id'],
					sign_time : parseInt(new Date().getTime() / 1000)
				}
				ret = utils.result(0, aes.encrypt(sign));
			}
		}
		res.json(ret);
	});
	
}